﻿@{
    ViewBag.Title = "补充保单信息";
}
@using ZBJF.Warranty.Common.Enums.Certificate
@using ZBJF.Warranty.Common.Enums.Data
@using ZBJF.Warranty.Common.Enums.InsuranceOrder
@using ZBJF.Warranty.WebProvider
@model ZBJF.Warranty.Model.InsuranceOrder

@using (Html.BeginForm("SaveUnComplementInsuranceOrder", "InsuranceOrder", FormMethod.Post, new { id = "mvcForm", name = "mvcForm", @class = "form-horizontal", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(c => c.ID)
    <table class="table table-responsive table-bordered table-hover">
        <tr>
            <th>保险产品类型：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceCategoryName, new {@class = "disabled-element" })
            </td>
            <th>保险产品名称：</th>
            <td>
                @Html.TextBoxFor(m => m.ProductName, new {@class = "disabled-element" })
            </td>
        </tr>
        <tr>
            <th>被保险设备：</th>
            <td>
                @Html.DropDownListFor(m => m.ProductTypeId, ConvertToSelector.Instance.ProductTypeConvertToSelectList(false), new { onchange = "productTypeChange()" })
                @Html.HiddenFor(m => m.ProductTypeName)
            </td>
            <th>证件类型：</th>
            <td>
                @Html.DropDownListFor(m => m.CertificateType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(UserCertificateType), addEmptySelect: false))
            </td>
        </tr>
        <tr>
            <th>第三方承保公司：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuranceCompany, new { Value = "平安产险", @class = "disabled-element" })
            </td>
            <th></th>
            <td>
            </td>
        </tr>
        <tr>
            <th>第三方唯一编号：</th>
            <td>
                @Html.TextBoxFor(m => m.ThirdUniqueNumber, new { validate = "{isRightfulStringNounderline:true}" })
            </td>
            <th>第三方保单号：</th>
            <td>
                @Html.TextBoxFor(m => m.ThirdOrderNO, new { validate = "{isRightfulStringNounderline:true}" })
            </td>
        </tr>
        <tr>
            <th>承保公司分公司：<span class="red">*</span></th>
            <td>
                <select name="InsuranceCompanyBranch" id="InsuranceCompanyBranch" validate="{required:true,messages:{required:'选择承保公司分公司'}}">
                    <option value="" selected="">选择承保公司分公司</option>
                    <option value="湖南分公司">湖南分公司</option>
                    <option value="上海分公司">上海分公司</option>
                    <option value="陕西分公司">陕西分公司</option>
                    <option value="四川分公司">四川分公司</option>
                    <option value="广东分公司">广东分公司</option>
                    <option value="江苏分公司">江苏分公司</option>
                    <option value="深圳分公司">深圳分公司</option>
                </select>
            </td>
            <th>被保险设备类型：<span class="red">*</span></th>
            <td>
                @Html.DropDownListFor(m => m.DeviceType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(InsuranceOrderDeviceType)), new { validate = "{required:true,messages:{required:'请选择被保险设备类型！'}}" })
            </td>
        </tr>
        <tr>
            <th>品牌：<span class="red">*</span></th>
            <td>
                @Html.TextBoxFor(m => m.ProductBrandName, new { validate = "{required:true,messages:{required:'请输入品牌！'}}" })
                @Html.HiddenFor(m => m.ProductBrandId)
            </td>
            <th>销售商户名称：<span class="red">*</span></th>
            <td>
                @Html.DropDownListFor(m => m.SaleVendorId, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(SaleVendorEnums)), new { validate = "{required:true,messages:{required:'请选择销售商户名称！'}}",@onchange = "Show()" })
                @Html.HiddenFor(m => m.SaleVendorName)
            </td>
        </tr>
        <tr>
            <th>机型：<span class="red">*</span></th>
            <td>
                @Html.TextBoxFor(m => m.ProductModelName, new { validate = "{required:true,messages:{required:'请输入机型！'}}" })
                @Html.HiddenFor(m => m.ProductModelId)
            </td>
            <th>设备识别码：</th>
            <td>
                @Html.TextBoxFor(m => m.IMEI, new { validate = "{isRightfulStringNounderline:true}" })
            </td>
        </tr>
        <tr>
            <th>被保险人姓名：<span class="red">*</span></th>
            <td>
                @Html.TextBoxFor(m => m.UserName, new { validate = "{required:true,messages:{required:'请填写被保险人姓名'}}" })
            </td>
            <th>投保日期</th>
            <td>
                @Html.TextBoxFor(m => m.CreateOrderTime, new { @class = "Wdate", onclick = "WdatePicker({maxDate:'" + DateTime.Now.ToString("yyyy-MM-dd") + "'})" })
            </td>
        </tr>
        <tr>
            <th>被保险人电话：<span class="red">*</span></th>
            <td>
                @Html.TextBoxFor(m => m.UserPhone, new { validate = "{required:true,isTelphone:true,messages:{required:'请填写被保险人电话'}}" })
            </td>
            <th>保险起期：</th>
            <td>
                @Html.TextBoxFor(m => m.ServiceStartTime, new { @class = "Wdate", onclick = "WdatePicker({maxDate:'#F{$dp.$D(\\'ServiceEndTime\\')||\\'" + DateTime.Now.ToString("yyyy-MM-dd") + "\\'}'})" })
            </td>
        </tr>
        <tr>
            <th>证件号码：</th>
            <td>
                @Html.TextBoxFor(m => m.CertificateNO, new { validate = "{isIdCardNo:true,messages:{required:'请填写证件号码'}}" })
            </td>
            <th>保险止期：</th>
            <td>
                @Html.TextBoxFor(m => m.ServiceEndTime, new { @class = "Wdate", onclick = "WdatePicker({minDate:'#F{$dp.$D(\\'ServiceStartTime\\')}'})" })
            </td>
        </tr>
        <tr>
            <th>保额：</th>
            <td>
                @Html.TextBoxFor(m => m.InsuredAmount, new {onkeyup = "onlyInputDecimal(this)"})
            </td>
            <th>保单状态：</th>
            <td>
                @Html.DropDownListFor(m => m.OrderStatus, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(InsuranceOrderStatus)), new { onkeyup = "onlyInputDecimal(this)" })
            </td>
        </tr>
    </table>
    <div class="form-actions">
        <input id="btnAuditAndPass" class="btn btn-primary Edit-R" type="submit" value="提交">
    </div>
}
@section scripts
{
    @Scripts.Render("~/bundles/autocomplete")
    @Styles.Render("~/Content/autocomplete")
    <script type="text/javascript">
        $(function () {
            Show();
            saleVendorIdChange();

            $("#InsuranceCompanyBranch").val("@Model.InsuranceCompanyBranch");

            $("#SaleVendorId").change(function () {
                saleVendorIdChange();
            });

            $("#ProductBrandName").autocomplete("/Common/GetProductBrandList", {
                cacheLength: 0, //缓存
                delay: 230, //延迟
                dataType: "json",
                parse: function (data) {
                    try {
                        return $.map(data, function (row) {
                            return {
                                data: row,
                                value: row.Value,
                                result: row.Text
                            }
                        });
                    } catch (e) {
                        return "";
                    }
                },
                formatItem: function (item, i, max) {
                    return item.Text;
                },
                formatResult: function (item) {
                    return item.Text;
                }
            }).result(function (event, data, formatted) {
                try {
                    $("#" + $(event.currentTarget).attr("id").replace("ProductBrandName", "ProductBrandId")).val(data.Value);
                } catch (e) {
                    $("#" + $(event.currentTarget).attr("id").replace("ProductBrandName", "ProductBrandId")).val("");
                }
            });

            $("#ProductModelName").autocomplete("/Common/GetProductModelListByBrandIdAndModelName", {
                cacheLength: 0, //缓存
                delay: 230, //延迟
                extraParams: { BrandId: function () { return $("#ProductBrandId").val() } },
                dataType: "json",
                parse: function (data) {
                    try {
                        return $.map(data, function (row) {
                            return {
                                data: row,
                                value: row.Value,
                                result: row.Text
                            }
                        });
                    } catch (e) {
                        return "";
                    }
                },
                formatItem: function (item, i, max) {
                    return item.Text;
                },
                formatResult: function (item) {
                    return item.Text;
                }
            }).result(function (event, data, formatted) {
                try {
                    $("#" + $(event.currentTarget).attr("id").replace("ProductModelName", "ProductModelId")).val(data.Value);
                } catch (e) {
                    $("#" + $(event.currentTarget).attr("id").replace("ProductModelName", "ProductModelId")).val("");
                }
            });
        });


        //是否禁用
        function Show() {
            debugger;
            var id = $("#SaleVendorId option:selected").val();
            if (id != 4){
                $("#CertificateNO").removeAttr("disabled").attr("validate", "{isIdCardNo:true,messages:{required:'请填写证件号码！'}}");
            } else {
                $("#CertificateNO").val("000000000000000000").attr("disabled", true).attr("validate", "{isIdCardNo:false}");
            }
        }


        function productTypeChange() {
            var typeName = $("#ProductTypeId option:selected").text();
            $("#ProductTypeName").val(typeName);
        }

        function saleVendorIdChange() {
            var typeName = $("#SaleVendorId option:selected").text();
            $("#SaleVendorName").val(typeName);
        }
    </script>
}
